import 'package:flutter/material.dart';


class FriendPage extends StatefulWidget {
  FriendPage({Key? key}) : super(key: key);

  @override
  _FriendPageState createState() => _FriendPageState();
}

class _FriendPageState extends State<FriendPage> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController? _tabController;
  List _spList = [
    "消息",
    "好友"
  ];
  @override
  void initState() {
    super.initState();
    _tabController = null;
    _tabController = TabController(
      initialIndex: 0,
      length: _spList.length,
       vsync: this
    );
  }
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Column(
        children: [
          Container(
            alignment: Alignment.centerLeft,
            child: TabBar(
              // indicator: const BoxDecoration(),
              controller: _tabController,
              isScrollable: true,
              labelColor: Colors.white,
              unselectedLabelColor: Colors.yellow,
              labelStyle: TextStyle(fontSize: 16),
              unselectedLabelStyle: TextStyle(fontSize: 30),
              indicatorWeight: 0.1,
              tabs: _spList.map((f) {
                return Center(
                  child: new Text(
                    f,
                    style: TextStyle(color: Colors.black, fontSize: 22),
                  ),
                );
              }).toList(),
            ),
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: _spList.isEmpty ? [] : _spList.map((f) {
                return Center(
                  child: ListView( children: <Widget>[
                    ListTile(title: Text("这是第一个 tab")),
                    ListTile(title: Text("这是第一个 tab")),
                    ListTile(title: Text("这是第一个 tab"))
                  ],),
                );
              }).toList()
            ),
          ),
        ]
      )
    );
  }

  @override
  bool get wantKeepAlive => true;
}